// 将普通数组转换为tree数组
module.exports = function (a, idStr, pidStr, chindrenStr) {
  const r = [];
  const hash = {};
  const id = idStr;
  const pid = pidStr;
  const children = chindrenStr;
  let i = 0;
  let j = 0;
  const len = a.length;
  for (; i < len; i++) {
    hash[a[i][id]] = a[i];
  }
  for (; j < len; j++) {
    const aVal = a[j];
    const hashVP = hash[aVal[pid]];
    if (hashVP) {
      !hashVP[children] && (hashVP[children] = []);
      hashVP[children].push(aVal);
    } else {
      r.push(aVal);
    }
  }
  return r;
};
